package everydayGrade.t4;

import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: Siantar
 * @Date: 2023-11-20-18:08
 * @Description: 1.0
 */
public class T0078 {
    public List<List<Integer>> subsets(int[] nums) {
        int n = nums.length;
        int mark = (1 << n) - 1;
        int t = mark;
        List<List<Integer>> res = new ArrayList<>();
        while (t > 0) {
            int s = t;
            List<Integer> list = new ArrayList<>();
            for (int i = 0; i < n - 1 && s > 0; i++, s = s >> 1) {
                if ((s & 1) > 0) {
                    list.add(nums[i]);
                }
            }
            res.add(list);
            t = (t - 1) & mark;
        }
        res.add(new ArrayList<>());
        return res;
    }

    @Test
    public void test() {
        subsets(new int[]{1, 2, 3});
    }
}
